FROM odoo:9.0

USER root

# Set the default config file
ENV ODOO_CONFIG="/etc/odoo/odoo.conf"

RUN ln -sf /usr/share/zoneinfo/America/Guayaquil /etc/localtime

RUN apt-get update && \
    apt-get install -y python-pandas git make default-jdk default-jre locales xz-utils && \
    rm -rf /var/lib/apt/lists/* && \
    curl -sL https://bootstrap.pypa.io/get-pip.py >> /tmp/get-pip.py && \
    python /tmp/get-pip.py && \
    rm -rf /tmp/get-pip.py

# Install wkhtmltopdf 0.12.4 (with patched qt)
RUN curl -sL https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz --output /tmp/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz && \
    tar -xvf /tmp/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz -C /tmp && \
    mv -i /tmp/wkhtmltox/bin/wkhtmlto* /usr/bin/ && \
    ln -nfs /usr/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf && \
    rm -rf /tmp/wkhtmltox*

RUN curl -sL https://github.com/ncopa/su-exec/archive/v0.2.tar.gz | tar -xz -C /tmp && \
    cd /tmp/su-exec-0.2 && make && mv su-exec /usr/bin

# OCA Repos
# https://github.com/OCA/maintainer-quality-tools/pull/404
ENV MQT_URI="https://github.com/arkhan/maintainer-quality-tools/archive/master.tar.gz"
RUN curl -sL "$MQT_URI" | tar -xz -C /opt/ \
    && ln -sf /opt/maintainer-quality-tools-*/travis/clone_oca_dependencies /usr/bin \
    && ln -sf /opt/maintainer-quality-tools-*/travis/getaddons.py /usr/bin \
    && chmod +x /usr/bin/getaddons.py

# PUDB debugger
RUN /usr/local/bin/pip install --no-cache-dir wdb watchdog

COPY ./docker-entrypoint.sh /entrypoint.sh

RUN chown odoo /entrypoint.sh && \
    chown -R odoo /etc/odoo && \
    chmod +x /entrypoint.sh

RUN mkdir -p /opt/odoo && \
    mkdir -p /mnt/repos && \
    chown -R odoo /opt/odoo && \
    chown -R odoo /mnt/repos

RUN locale-gen es_EC.UTF-8 && \
    dpkg-reconfigure --frontend=noninteractive locales

ENV LANG es_EC.UTF-8
ENV LC_ALL C.UTF-8

RUN update-locale

# Path to cusrtom odoo repos
VOLUME ["/mnt/repos"]

# Entrypoint & Cmd
ENTRYPOINT ["/entrypoint.sh"]

CMD ["openerp-server"]
